package com.huyun.web.modules.threadLocal;

import java.util.ArrayList;
import java.util.List;

/**
 * @author huyunqiang
 * @Date 2019/8/20 16:21
 */

public class ThreadLocalDemo {

    public static ThreadLocal<List<String>> threadLocal = new ThreadLocal<>();

    public  void setThreadLocal(List<String> values) {
        threadLocal.set(values);
    }

    public void getThreadLocal(){
        threadLocal.get().forEach(name ->
                System.out.println(Thread.currentThread().getName()+":"+name));
    }

    public static void main(String[] args) {
        final ThreadLocalDemo threadLocal = new ThreadLocalDemo();

        new Thread(() ->{
            List<String> list = new ArrayList<>();
            list.add("hu");
            list.add("yun");
            list.add("qiang");
            threadLocal.setThreadLocal(list);
            threadLocal.getThreadLocal();
        }).start();

        new Thread(() ->{
            List<String> list = new ArrayList<>();
            list.add("nihoa");
            list.add("buhao");
            threadLocal.setThreadLocal(list);
            threadLocal.getThreadLocal();
        }).start();
    }


}
